package com.darrenchan.course08

import java.io.File

import scala.io.Source

object MyPredef {
  implicit def fileToRichFile(f: File) = {
    new RichFile(f)
  }
}

class RichFile(val f: File) {
  def read(): String = {
    Source.fromFile(f).mkString
  }
}

object RichFile {
  def main(args: Array[String]): Unit = {
    val f = new File("D:\\hello.txt")
    //装饰 显式增强
    //val contents = new RichFile(f).read()

    //隐式
    import MyPredef._
//    implicit def fileToRichFile(f: File) = {
//      new RichFile(f)
//    }
    val contents = f.read()
    println(contents)
  }
}
